package com.kuang.annotation;

import java.lang.annotation.*;
import java.lang.reflect.Field;

public class test12 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class stu1 = Class.forName("com.kuang.annotation.Student02");
        //通过反射获得注解
        Annotation[] annotations = stu1.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }
        //获得注解的value值
        Typedu tabledu = (Typedu)stu1.getAnnotation(Typedu.class);
        String value = tabledu.value();
        System.out.println(value);
        System.out.println("**************");
        Field name = stu1.getDeclaredField("id");
        Fielddu nameTy = name.getAnnotation(Fielddu.class);
//        String s = annotation.columName();
//        int length = annotation.length();
//        String type = annotation.type();
        System.out.println(nameTy.personName()+"///"+nameTy.length()+"///"+nameTy.type());


    }
}
@Typedu("db_student")
class Student02{
    @Fielddu(personName = "db_name",type="varchar",length = 10)
    private String name;
    @Fielddu(personName = "db_age",type="int",length = 2)
    private int age;
    @Fielddu(personName = "db_id",type="int",length = 8)
    private int id;

    public Student02() {
    }

    public Student02(String name, int age, int id) {
        this.name = name;
        this.age = age;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Student02{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                '}';
    }
}

//类名的注解
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface Typedu{
    String value();
}


//属性的注解
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface Fielddu{
    String personName();
    String type();
    int length();
}